<?php

    class Application_Form_LoginForm extends Zend_Form
    {

        protected $step = 1;
        protected $email;

        public function setStep($param)
        {
            if (empty($param))
            {
                $this->step = 1;
                return $this;
            }

            $this->step = $param;
            return $this;
        }

        public function setEmail($param)
        {
            $this->email = $param;
            return $this;
        }

        public function init()
        {
            switch ($this->step)
            {
                case 1: $this->emailForm($this->step);
                    break;
                case 2: $this->detailedForm($this->step);
                    break;
                case 'main': $this->mainloginForm();
                    break;
            }
        }

        public function mainloginForm()
        {


            $this->addElement("text", "email_address", array(
                "placeholder" => "Email/Username",
                "required" => true,
                "class" => "form-control required email",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", "EmailAddress", array('StringLength', false, array('max' => 150))),
            ));
            
            $this->addElement("password", "password", array(
                "placeholder" => "Password",
                "required" => true,
                "class" => "form-control required",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty",array('StringLength', false, array('max' => 150,'min'=>6))),
            ));


            
            
            $elements = $this->getElements();
            foreach ($elements as $element)
            {
                $element->removeDecorator("DtDdWrapper")->removeDecorator("HtmlTag")->removeDecorator("Label");
            }
        }

        public function emailForm()
        {

            $this->addElement("text", "email_address", array(
                "placeholder" => "Email/Username",
                "required" => true,
                "class" => "form-control required email",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", "EmailAddress", array('StringLength', false, array('max' => 150))),
            ));


            $this->addElement("checkbox", "agree", array(
                "required" => true,
                "class" => "required",
                "filters" => array("StringTrim")
            ));

//
            $this->addElement('button', 'submit', array(
                'label' => 'LOGIN',
                'class' => 'btn btn-raeken-signup btn-block',
                'type' => 'submit',
                'buttonType' => 'register',
                'escape' => false
            ));

            $elements = $this->getElements();
            foreach ($elements as $element)
            {
                $element->removeDecorator("DtDdWrapper")->removeDecorator("HtmlTag")->removeDecorator("Label");
            }
        }

        public function detailedForm()
        {

            $this->addElement("text", "email_address", array(
                "placeholder" => "Email/Username",
                "required" => true,
                "class" => "form-control required email",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", "EmailAddress", array('StringLength', false, array('max' => 150))),
            ));


            if ($this->email != "")
                $this->email_address->setValue($this->email);

            $this->addElement("text", "first_name", array(
                "required" => true,
                "class" => "form-control required",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", array('StringLength', false, array('max' => 150))),
            ));

            $this->addElement("text", "last_name", array(
                "required" => true,
                "class" => "form-control required",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", array('StringLength', false, array('max' => 150))),
            ));

            $this->addElement("text", "username", array(
                "required" => true,
                "class" => "form-control required",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", array('StringLength', false, array('max' => 150, 'min' => 3))),
            ));

            $this->addElement("password", "password1", array(
                "required" => true,
                "class" => "form-control required",
                "minlength" => "6",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", array('StringLength', false, array('max' => 150, 'min' => 3))),
            ));

            $this->addElement("password", "confirm_password", array(
                "required" => true,
                "class" => "form-control required",
                "equalto" => "#password1",
                "minlength" => "6",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", array('StringLength', false, array('max' => 150, 'min' => 3))),
            ));
            
            $this->addElement("text", "zip_code", array(
                "required" => true,
                "class" => "form-control required",
                "maxlength" => "10",
                "minlength" => "3",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty", array('StringLength', false, array('max' => 10, 'min' => 3))),
            ));
            
            
            $this->addElement("text", "address", array(
                "required" => true,
                "class" => "form-control required",
                "filters" => array("StringTrim"),
                "validators" => array("NotEmpty")
            ));
            
            


            $this->confirm_password->addValidator(new Zend_Validate_Identical($_POST['password1']));



            $elements = $this->getElements();
            foreach ($elements as $element)
            {
                $element->removeDecorator("DtDdWrapper")->removeDecorator("HtmlTag")->removeDecorator("Label");
            }
        }

    }

    